package com.qianxiwitmanagement.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxi.wit.pojo.TbConsult;
import com.qianxi.wit.pojo.TbDoctor;
import com.qianxi.wit.result.R;
import com.qianxiwitmanagement.service.TbConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqp
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/consult")
public class TbConsultController {
    @Autowired
    private TbConsultService consultService;

    //快速问诊医生列表页面，查询时绑定doctor对象中的doctor_name属性去查询
    @PostMapping("/findDoctor/{page}/{size}/{ids}")
    public R findDoctor(@PathVariable("page") int page,
                        @PathVariable("size") int size,
                        @PathVariable("ids") Long[] ids,
                        @RequestBody TbDoctor doctor){
        try {
            Page<TbDoctor> page1 = consultService.findbydoctor(page,size,ids,doctor);
            return R.ok().data("page",page1.getCurrent()).data("size",page1.getTotal()).data("total",page1.getTotal()).data("list",page1.getRecords());
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    //点击咨询，生成问诊记录[订单]
    @PostMapping("/insert")
    public R insert(@RequestBody TbConsult consult){
        try {
            TbConsult consult1 = consultService.insert(consult);
            return R.ok().data("consult",consult1);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PostMapping("/patientName")
    public R list(){
        try {
            //获取当前登录人的令牌
            String patientName = "李四";
            List<TbConsult> list = consultService.selectList(patientName);
            return R.ok().data("list",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}

